package org.marlin.http.handler;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.springframework.beans.BeansException;

public abstract class HttpHandlerAssist
        implements HttpHandler {
    private static Map<Class, HttpHandler> HTTP_HANDLER_MAP = (Map) new ConcurrentHashMap<>();

    protected static synchronized void add(HttpHandler httpHandler) {
        if (HTTP_HANDLER_MAP == null) {
            HTTP_HANDLER_MAP = (Map) new ConcurrentHashMap<>();
        }
        HTTP_HANDLER_MAP.put(httpHandler.getClass(), httpHandler);
    }

    public static Map<Class, HttpHandler> getHttpHandlerMap() {
        return HTTP_HANDLER_MAP;
    }


    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        add(this);
        return bean;
    }
}

